package com.learn.spring.event.service.impl;

import com.learn.spring.event.message.PlaceOrderEventMessage;
import com.learn.spring.event.order.PlaceOrderEvent;
import com.learn.spring.event.order.PlaceOrderReqVO;
import com.learn.spring.event.order.PlaceOrderResVO;
import com.learn.spring.event.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

/**
 * 订单实现类-被观察者实现类
 *
 * @author cong zhi
 * @email 448341911@qq.com
 * @createDate 2023/3/20 16:49
 * @version: v1.0
 */
@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    @Override
    public PlaceOrderResVO placeOrder(PlaceOrderReqVO reqVO) {
        log.info("[placeOrder] start.");
        PlaceOrderResVO resVO = new PlaceOrderResVO();
        //消息
        PlaceOrderEventMessage eventMessage = new PlaceOrderEventMessage();
        // 发布事件
        applicationEventPublisher.publishEvent(new PlaceOrderEvent(eventMessage));
        log.info("[placeOrder] end.");
        return resVO;
    }
}
